package com.lxf.cn.user;

import com.alibaba.fastjson.JSONObject;
import org.springframework.stereotype.Controller;
import org.springframework.util.Assert;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpSession;

/**
 * Created by liaoxuefeng on 2018/12/6.
 */

@Controller
public class UserController {

    /**
     *
     * @return
     */
    @RequestMapping(value = "/index" , method = RequestMethod.GET)
    public String login(){
        return "index.html";
    }


    /**
     *
     * @param params
     * @param session
     * @return
     */
    @RequestMapping("login")
    public @ResponseBody Object landing(@RequestBody JSONObject params , HttpSession session){

        String name = params.getString("name");
        Assert.notNull(name , "用户名不能为空");
        String pwd = params.getString("pwd");
        Assert.notNull(pwd , "密码不能为空");

        session.setAttribute("user" , params);

        return 1 ;

    }

    /**
     * 返回登录成功
     * @return
     */
    @RequestMapping("/main")
    public String index(){
        return "main.html";
    }




}
